import  instance from '../utils/index'
// 进行登录
const GetLogin=(params)=>instance.post('/login',params)

// 左边侧边栏
const menusList=()=>instance.get('/menus')

// 用户模块 只有get请求符合字符串拼接方式
const userList = (params) =>instance.get('/users',{params}) //get请求 传参需要对象{}获取

//添加用户
const addUser = (msg) => instance.post('/users',msg)

// 删除用户
const deluser = (msg) => instance.delete(`users/${msg}`)

// 根据id查找用户
// const getUserById = (msg) => instance.get(`users/${msg}`)

// 状态
const changestatus = (msg) => instance.put(`/users/${msg.id}/state/${msg.mg_state}`)

// 修改编辑用户
const edituser = (ruleForm1,state) =>instance.put(`/users/${ruleForm1}`,{email: state.email, mobile:state.mobile})

// 分配角色 点击对话框
const roleuser = () =>instance.get('/roles')

// 分配用户角色
 const changrole = (obj,rid) => instance.put(`/users/${obj.id}/role`,{rid:rid})


 // 权限管理模块
 //角色列表
 const rolelist = () => instance.get('/roles')

 // 添加角色
 const addRole = (msg) => instance.post('/roles',msg)
 
 //删除角色
 const delrole = (msg) => instance.delete(`roles/${msg}`)
 
// 点击确定 执行修改
const editrole = (form1,state) => instance.put(`/roles/${form1}`,{roleName:state.roleName ,roleDesc:state.roleDesc})

// 获取所有权限列表的数据
const rightslist = ()=> instance.get(`/rights/tree`)

// 角色授权接口 请求数据
const getrole = (roleId,rids) =>instance.post(`/roles/${roleId}/rights`,{rids})

// 商品所有数据
const goodList = (params) => instance.get("/goods",{params})

// 删除商品
const delGoods = (id) => instance.delete(`goods/${id}`)

// 添加商品接口
const addGoods = (obj) => instance.post('/goods',obj)
// 获取商品分类所有的数据
const cateList = (obj) => instance.get('/categories' ,{params:obj})

// 添加分类
const addcate = (msg) => instance.post ('/categories',msg)

// 两层三级分类
const  towlist = () => instance.get('/categories?type=2')
 // 三层三级分类
const threelist = () => instance.get('/categories?type=3')
// 删除分类
const delCate = (id) => instance.delete(`categories/${id}`)

// 请求分类参数所有的数据‘
const attrlist = (id,sel) =>instance.get(`categories/${id}/attributes`,{params:sel})

// 删除参数或者属性
const delAttr = (id,rid)=>instance.delete(`categories/${id}/attributes/${rid}`)

// 点击对话框确定按钮 添加动态参数
const addAtt = (id,obj)=> instance.post(`categories/${id}/attributes`,obj)

// 提交更新参数属性
const updateAttr = (res) => instance.put(`categories/${res.id}/attributes/${res.attr_id}`,{attr_name:res.attr_name,attr_sel:res.attr_sel,attr_vals:res.attr_vals})
export{ GetLogin,addGoods, threelist,goodList,delGoods,updateAttr,menusList,addAtt,delAttr,attrlist,addcate ,delCate,towlist,userList,addUser,deluser,changestatus,edituser,roleuser,changrole,rolelist,addRole,delrole,editrole,rightslist,getrole,cateList}